<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模态框案例</title>
    <script src="../vue.js"></script>
    <style>
        #overlay{
            background-color: rgba(0,0,0,0.4);
            position: fixed;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;

        }
        #center{
            background-color: white;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            min-height: 100px;
            padding: 20px;
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <div id="box">
        <button @click="isShow=!isShow">模态框</button>
        <!-- 方法一,子元素阻止冒泡 .stop -->
        <!-- <div id="overlay" v-show="isShow" @click="isShow=false">
            <div id="center" @click.stop>
                用户名: <input type="text">
                <button>登录</button>
            </div>
        </div> -->
        <!-- 方法二  父元素添加  .self 只有事件源是它本身时才会触发-->
        <div id="overlay" v-show="isShow" @click.self="isShow=false">
            <div id="center">
                用户名: <input type="text">
                <button>登录</button>
            </div>
        </div>
    </div>
    <script>
        let obj = {
            data() {
                return {
                    isShow: false,
                }
            },
           
        }
        Vue.createApp(obj).mount('#box')
    </script>
</body>
</html>